/*****************************************************************************
*  data collect api definition                                               *
*  Copyright (C) 2022 EXCCEDDATA.                                            *
*                                                                            *
*  This file is part of OST.                                                 *
*                                                                            *
*  This header file describes the interfaces of data collect,                *
*  including enums, structs and classes                                      *
*  published by the Free Software Foundation.                                *
*                                                                            *
*  @file     DataCollectSourceAPI.h                                          *
*  @brief    This header file describes the interfaces of data collect,      *
*  including enums, structs and classes                                      *
*  published by the Free Software Foundation.                                *
*                                                                            *
*  @author   EXCCEDDATA                                                      *
*  @version  1.0.0                                                           *
*  @date     2022/07/18                                                      *
*  @license                                                                  *
*                                                                            *
*----------------------------------------------------------------------------*
*  Remark         : Description                                              *
*----------------------------------------------------------------------------*
*  Change History :                                                          *
*  <Date>     | <Version> | <Author>       | <Description>                   *
*----------------------------------------------------------------------------*
*  2022/07/18 | 1.0.0     | EXCCEDDATA     | Create file                     *
*----------------------------------------------------------------------------*
*                                                                            *
*****************************************************************************/

/* source data id define */
enum DataidType {
    DT_NORMAL = 0,  /* ordinary signal data */
    DT_CAMERA = 1,	/* camera data */
};

/* data encode type define */
enum class EncodeType : std::uint8_t /* use 8 bit to define every encode type */
{
	ET_ORIGINAL = 0,      /* not encoded */
    ET_JPEG     = 1,      /* JPEG encoded */
};

/* transmit data struct of nostructed data */
struct  BinaryDataInfo
{
	char*        dataBuf;              /* data content */
	uint32_t     dataSize;             /* size of data content */
	uint64_t     nsec;                 /* timestamp represents the time when the data generated, unit is nanosecond */
	DataidType   dataidType;	       /* channel id of the data */
    EncodeType   encodeType;           /* encode type of the data */
};

/* transmit data struct of nostructed data */
enum RetCode 
{
    RET_OK = 0,                     /* data content */
    RET_INVALID_DATAID = 1,         /* data content */
    RET_TIMEOUT = 2,                /* operation time out */

    RET_UNKNOWN=99                  /* unknown error */
};


/* transmit controll interface */
class IDataTransControlCallback
{
public:
    IDataTransControlCallback() = default;
    virtual ~IDataTransControlCallback() = default;

    /**
    * @brief app could call this interface to control transmit data or not.
    * @param[in] enable true--enalbe transmit, false--disable transmit.
    * 
    * @return
    * - void
    */
    virtual void DataTransEnable(bool enable) = 0;
};

/*****************************************
* data collect class
* we only define methods that needed for camera manage instance,
* and a pointer to the object which is created by this class instance, 
* the object implements most of the functions, 
* such as caching data, uploding files and so on
*
*****************************************/
class DataCollectSource {
public:
    /**
    * @brief construct method.
    * @param[in] serviceID specify which service creates this object.
    */
    DataCollectSource(uint32_t serviceID);
    virtual ~DataCollectSource();

public:
    /**
    * @brief register the dataID for camera sensor.
    * @param[in] dataID represents the specific sensor id, fps and image format.
    * @param[in] callback provides a function to control whether transmit image data or not.
    * 
    * @return
    * - RET_OK, success
    * - RET_INVALID_DATAID, unknown source data id
    *
    * @note callback should be saved into a map, used to enbale or disable transimit in the future.
    * usage: callback->dataTransEnable(false/true);
    */
    RetCode RegisterDataSource(const std::string& dataID, 
                               IDataTransControlCallback* callback, 
                               DataidType dataidType = DataidType::DT_NORMAL);

    /**
    * @brief unregister the dataID for camera sensor.
    * @param[in] dataid represents the specific sensor id, fps and image format.
    *
    * @return
    * - RET_OK, success
    * - RET_INVALID_DATAID, unknown source data id
    */
    RetCode UnregisterDataSource(const std::string& dataID);

    /**
    * @brief camera manage instance calls this method to transmit data to data collector
    * @param[in] dataID represents the specific sensor id, fps and image format.
    * @param[in] dataInfo the struct that contains the data, data descriptions.
    * 
    * @return
    * - RET_OK, success
    * - RET_INVALID_DATAID, unknown source data id
    */
    RetCode WriteData(const std::string &dataID, 
                      const BinaryDataInfo &dataInfo);

private:
    /** 
    * @brief ponit to the object that implements the functions, 
    * such as caching data, uploding files and so on
    */
    void* m_pImp = nullptr;
};
